import axios from 'axios'
import { getToken } from '@/utils/auth'


export function exportFile(func,para) {
  let baseURL = process.env.VUE_APP_BASE_API
  axios({
    method: 'get',
    url:  baseURL + func +  '?' + para ,
    headers: {
      'Authorization' : getToken()
    },
    responseType: "blob"
  })
    .then(res => {
      console.log(res)
      if (res.data.type) {
        // 文件下载
        const blob = new Blob([res.data], {
          type: "application/vnd.ms-excel"
        });
        let link = document.createElement('a');
        link.href = URL.createObjectURL(blob);
        link.setAttribute('download', '导出文件.xlsx');
        link.click();
        link = null;
        return 'success'
      } else {
        // 返回json
        return 'warning'
      }
    })
    .catch(err => {
      return 'error'
    });
}
